package com.yqya.springboot.mybatisplus.shardingjdbc.biz.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yqya.springboot.mybatisplus.shardingjdbc.biz.UserInfoBizService;
import com.yqya.springboot.mybatisplus.shardingjdbc.domain.UserInfo;
import com.yqya.springboot.mybatisplus.shardingjdbc.dto.UserInfoDTO;
import com.yqya.springboot.mybatisplus.shardingjdbc.service.UserInfoService;
import com.yqya.springboot.mybatisplus.shardingjdbc.vo.UserInfoVO;

/**
 * 用户信息业务服务接口实现类
 *
 * @author Kevin
 * @date 2019-08-03
 */
@Service
public class UserInfoBizServiceImpl implements UserInfoBizService {

    @Autowired
    private UserInfoService userInfoService;

    @Override
    public UserInfoVO saveUserInfo(UserInfoDTO dto) {
        UserInfo item = new UserInfo();
        item.setId(dto.getId());
        item.setName(dto.getName());
        item.setAge(dto.getAge());
        userInfoService.save(item);

        UserInfoVO vo = new UserInfoVO();
        BeanUtils.copyProperties(item, vo);

        return vo;
    }

    @Override
    public UserInfoVO findById(Long id) {
        UserInfo item = userInfoService.getById(id);
        UserInfoVO vo = new UserInfoVO();
        if (item != null) {
            BeanUtils.copyProperties(item, vo);
        }
        return vo;
    }

}
